package org.light.complexverb;

import java.util.ArrayList;
import java.util.List;

import org.light.core.Writeable;
import org.light.domain.Domain;
import org.light.domain.Method;
import org.light.domain.Signature;
import org.light.domain.Statement;
import org.light.domain.Type;
import org.light.utils.StringUtil;
import org.light.utils.WriteableUtil;

public class MtmUtilMethodGenerator {
	public static Method generateExistsInArrMethod(Domain domain){
		Method method = new Method();
		method.setStandardName("existsIn"+StringUtil.capFirst(domain.getStandardName())+"Arr");
		method.setReturnType(new Type("bool"));
		method.addSignature(new Signature(2, domain.getLowerFirstPlural(),new Type("[] " +domain.getDomainSuffix()+ "." + domain.getType())));
		method.addSignature(new Signature(2, domain.getLowerFirstDomainName(),new Type(domain.getDomainSuffix()+ "." + domain.getType())));
		
		List<Writeable> sList = new ArrayList<Writeable>();
		sList.add(new Statement(1000L,1,"for _, v := range "+domain.getLowerFirstPlural()+" {"));
		sList.add(new Statement(2000L,2,"if "+domain.getLowerFirstDomainName()+".Get"+domain.getDomainId().getCapFirstFieldName()+"() == v.Get"+domain.getDomainId().getCapFirstFieldName()+"() {"));
		sList.add(new Statement(3000L,3,"return true"));
		sList.add(new Statement(4000L,2,"}"));
		sList.add(new Statement(5000L,1,"}"));
		sList.add(new Statement(6000L,1,"return false"));
		method.setMethodStatementList(WriteableUtil.merge(sList));
		return method;
	}
}
